/*-------------------------------- Arctic Core ------------------------------
 * Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
 * Contact: <contact@arccore.com>
 * 
 * You may ONLY use this file:
 * 1)if you have a valid commercial ArcCore license and then in accordance with  
 * the terms contained in the written license agreement between you and ArcCore, 
 * or alternatively
 * 2)if you follow the terms found in GNU General Public License version 2 as 
 * published by the Free Software Foundation and appearing in the file 
 * LICENSE.GPL included in the packaging of this file or here 
 * <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
 *-------------------------------- Arctic Core -----------------------------*/

/* Generator version: 4.0.0
 * AUTOSAR version:   4.0.3
 */

/* File: LinIf_Lcfg.c
 * Link time configurable parameters.
 *
 * Note: All time declarations are given in milliseconds.
 *       Time declarations are: LinIfTimeBase, LinIfDelay.
 */

#include "LinIf.h"

/*-----------[LinIf Frames]---------------------------------------------------*/

const LinIf_FrameType LinIfFrameCfg[LINIF_FRAMES_CNT] =
{
    /* ENG_TX_01 on channel LinIfChannel1 */
    {
        .LinIfChecksumType  = ENHANCED,
        .LinIfFrameName     = NULL_PTR, /* not used */
        .LinIfFramePriority = 0,        /* not used */
        .LinIfFrameType     = UNCONDITIONAL,
        .LinIfLength        = 8,
		.LinIfPid           = 139,
        .LinIfTxTargetPduId = PDUR_PDU_ID_ENG_TX,
        .LinIfFixedFrameSdu = NULL_PTR,
        .LinIfPduDirection  = LinIfTxPdu
    },
    /* ENG_RX_01 on channel LinIfChannel1 */
    {
        .LinIfChecksumType  = ENHANCED,
        .LinIfFrameName     = NULL_PTR, /* not used */
        .LinIfFramePriority = 0,        /* not used */
        .LinIfFrameType     = UNCONDITIONAL,
        .LinIfLength        = 4,
		.LinIfPid           = 142,
        .LinIfTxTargetPduId = PDUR_PDU_ID_LAMPS_RX,
        .LinIfFixedFrameSdu = NULL_PTR,
        .LinIfPduDirection  = LinIfRxPdu
    },
    /* ENG_RX_02 on channel LinIfChannel1 */
    {
        .LinIfChecksumType  = ENHANCED,
        .LinIfFrameName     = NULL_PTR, /* not used */
        .LinIfFramePriority = 0,        /* not used */
        .LinIfFrameType     = UNCONDITIONAL,
        .LinIfLength        = 8,
		.LinIfPid           = 146,
        .LinIfTxTargetPduId = PDUR_PDU_ID_TCM_RX,
        .LinIfFixedFrameSdu = NULL_PTR,
        .LinIfPduDirection  = LinIfRxPdu
    },
};



/*-----------[Entries for each schedule table]--------------------------------*/
/** @req LINIF506 */
/* Entries in schedule table SCHEDULE_01 on channel LinIfChannel1 */
const LinIfEntryType LinIfScheduleTable_Entries_1[3] =
{
    {
        .LinIfDelay                 = 10,
        .LinIfEntryIndex            = 0,
        .LinIfCollisionResolvingRef = (uint16) -1, /* not used */
        .LinIfFrameRef              = 0   // -> ENG_TX_01
    },
    {
        .LinIfDelay                 = 15,
        .LinIfEntryIndex            = 1,
        .LinIfCollisionResolvingRef = (uint16) -1, /* not used */
        .LinIfFrameRef              = 1   // -> ENG_RX_01
    },
    {
        .LinIfDelay                 = 25,
        .LinIfEntryIndex            = 2,
        .LinIfCollisionResolvingRef = (uint16) -1, /* not used */
        .LinIfFrameRef              = 2   // -> ENG_RX_02
    },
};


/*-----------[Schedule tables]------------------------------------------------*/
/* All schedule tables on all channels.
 * The schedule table with index 0 is the NULL_SCHEDULE table which is
 * autogenerated. */

const LinIf_ScheduleTableType LinIfScheduleTableCfg[LINIF_SCH_CNT] =
{
    /* NULL_SCHEDULE */ /** @req LINIF263 */
    [NULL_SCHEDULE] =
    {
        .LinIfResumePosition     = START_FROM_BEGINNING,
        .LinIfRunMode            = RUN_CONTINUOUS,
        .LinIfSchedulePriority   = 1,
        .LinIfScheduleTableIndex = NULL_SCHEDULE,
        .LinIfScheduleTableName  = "NULL_SCHEDULE",
        /* Null schedule table has 0 entries */
        .LinIfEntry              = NULL_PTR,
        .LinIfNofEntries         = 0,
    },
    /* SCHEDULE_01 on channel LinIfChannel1 */
    [LinIfConf_LinIfScheduleTable_SCHEDULE_01] =
    {
        .LinIfResumePosition     = START_FROM_BEGINNING,
        .LinIfRunMode            = RUN_CONTINUOUS,
        .LinIfSchedulePriority   = 1,        /* not used */
        .LinIfScheduleTableIndex = LinIfConf_LinIfScheduleTable_SCHEDULE_01,
        .LinIfScheduleTableName  = NULL_PTR, /* not used */
        .LinIfEntry              = LinIfScheduleTable_Entries_1,
        .LinIfNofEntries         = 3
    },
};

/*-----------[Channels]-------------------------------------------------------*/
/* LinIf Channel configurations.
 */
const LinIf_ChannelType LinIfChannelCfg[LINIF_CHANNEL_COUNT] =
{
    /* LinIfChannel1, referencing Lin channel LinChannel1 */
    {
        .LinIfLinChannelId               = LinConf_LinChannel_LinChannel1,
        .LinIfScheduleRequestQueueLength = 1,        // not used
        .LinIfFrame                      = NULL_PTR, // not used
        .LinIfMaster={.LinIfJitter         = 0},	//not used
        .LinIfScheduleTable              = &(LinIfScheduleTableCfg[NULL_SCHEDULE]),      /* @req LINIF231 */
        .LinIfSlave                      = NULL_PTR, // Master only
        .LinIfWakeUpSource               = NULL_PTR,  // Not needed
        .LinIfComMHandle				 = 0,
        .LinIfStartupState				 = LINIF_CHANNEL_SLEEP,
        .LinIfSleepTransitionCycle       = 4
    },
};

/* Map ComM channel Id to the corresponding CanSM index */
const NetworkHandleType ComMHandleToLinIfIndex[1] = {
	[0u] = 0u,/* ComMChannel1 -> LinIfChannel1 */
};

/*-----------[Module configuration]-------------------------------------------*/

const LinIf_ConfigType LinIf_Config =
{
    /* 5 milliseconds timebase */
    .LinIfTimeBase = 5,

    /* list of all 1 channels */
    .LinIfChannel  = LinIfChannelCfg,
    
	/*Pointer to Frame configuration */
    .LinIfFrameConfig = LinIfFrameCfg,
    
    .LinIfChannelMap = ComMHandleToLinIfIndex,
    .LinIfChannelMapSize = 1,
};
